if (!isObject(GhostCollisionBehavior)) {
   %template = new BehaviorTemplate(GhostCollisionBehavior);
   
   %template.friendlyName = "Ghost Collision Behavior";
   %template.behaviorType = "Envia Colision";
   %template.description  = "Colision entre un fantasma y pacman";
}

function GhostCollisionBehavior::dealDamage(%this, %victim) {
	%element = %victim.getBehavior("PacmanCollisionBehavior");
	if (isObject(%element)) {
		%element.takeDamage(%this);
		%this.goDirection();
		return;
	} 
	
	%element = %victim.getBehavior("DotCollisionBehavior");
	if (isObject(%element)) {
		%element.dontCollide(%this);
		return;
	}
	
	%this.goDirection();
}

function GhostCollisionBehavior::goDirection(%this) {
	%this.owner.setLinearVelocityY(0);
	%this.owner.setLinearVelocityX(0);
	
	%direction = getRandom(1,4);
	
	if (%direction == 1) {
		%this.owner.setLinearVelocityY(-3);
		return;
	}	
	if (%direction == 2) {
		%this.owner.setLinearVelocityX(3);
		return;
	}	
	if (%direction == 3) {
		%this.owner.setLinearVelocityY(3);
		return;
	}	
	if (%direction == 4) {
		%this.owner.setLinearVelocityX(-3);
		return;
	}	   
}

function GhostCollisionBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) {
	%this.dealDamage(%dstObj);
}